import java.util.ArrayList;

public class WeatherData implements MySubject {
	private ArrayList<MyObserver> observers;
	private float temmperature;
	private float humidity;
	private float pressure;
	
	public WeatherData() {
		observers = new ArrayList<MyObserver>();
	}
	@Override
	public void registerMyObserver(MyObserver o) {
		observers.add(o);
	}

	@Override
	public void removeMyObserver(MyObserver o) {
		int i = observers.indexOf(o);
		if(i>=0){
			observers.remove(i);
		}
	}

	@Override
	public void notifyMyObserver() {
		for (int i = 0; i < observers.size(); i++) {
			MyObserver observer = (MyObserver)observers.get(i);
			observer.update(this);
		}
	}
	
	public void measurementsChanged() {
		notifyMyObserver();
	}
	
	public void  setMeasurements(float temperature, float humidity, float pressure) {
		this.temmperature = temperature;
		this.humidity = humidity;
		this.pressure = pressure;
		measurementsChanged();
	}
	
	public float getTemperature() {
		return this.temmperature;
	}
	
	public float getHumidity() {
		return this.humidity;
	}
	
	public float getPressure() {
		return this.pressure;
	}

}
